package com.yodawnla.attackTitan2.scene;

import org.anddev.andengine.entity.sprite.Sprite;

import android.view.KeyEvent;

import com.yodawnla.attackTitan2.Player;
import com.yodawnla.attackTitan2.system.SE;
import com.yodawnla.attackTitan2.system.Tex;
import com.yodawnla.lib.YoScene;
import com.yodawnla.lib.util.widget.YoButton;

public class EndScene extends YoScene
{
	int mEnding = 0;
	Sprite mEnd0;
	Sprite mEnd1;
	Sprite mEnd2;
	
	static EndScene instance;
	public static EndScene getInstance()
	{
		if (instance == null)
			instance = new EndScene();
		return instance;
	}
	
	@Override
	public void loadScene()
	{
		mEnd0 = new Sprite(0, 0, getTexture(Tex.End));
		attachChild(mEnd0);
		mEnd1 = new Sprite(0, 0, getTexture(Tex.End1));
		attachChild(mEnd1);
		mEnd2 = new Sprite(0, 0, getTexture(Tex.End2));
		attachChild(mEnd2);
		
		YoButton backBtn = new YoButton(this,412, 18, getTexture(Tex.CloseBtn))
		{
			public void onClickedEvent()
			{
				playSound(SE.Click);
				toScene("TitleScene");
			}
		};
		this.attachChild(backBtn);	
	}
	
	public void setEnding(int index)
	{
		mEnding = index;
	}
	 
	@Override
	public void onEnterScene()
	{
		switch(mEnding)
		{
		case 0:
			mEnd0.setVisible(true);
			mEnd1.setVisible(false);
			mEnd2.setVisible(false);
			Player.getInstance().unlockHard();
			break;
		case 1:
			mEnd0.setVisible(false);
			mEnd1.setVisible(true);
			mEnd2.setVisible(false);
			Player.getInstance().unlockHard2();
			break;
		case 2:
			mEnd0.setVisible(false);
			mEnd1.setVisible(false);
			mEnd2.setVisible(true);
			Player.getInstance().unlockHard3();
			break;
		}
		
		setAdVisible(false);
		stopAllMusic();
		playSound(SE.End);
	}
	
	@Override
	public void onExitScene()
	{
		setAdVisible(true);
		/*unloadMarkedTexturePacks();
		cleanScene();*/
	}
	
	@Override
	public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) 
	{
		if(pKeyCode == KeyEvent.KEYCODE_BACK && pEvent.getAction() == KeyEvent.ACTION_DOWN)
		{
			playSound(SE.Click);
			toScene("TitleScene");
			return true;
		}
		return false;
	}
}